package com.yz.rabbitmq.limit;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.ConfirmListener;
import com.rabbitmq.client.Return;
import com.rabbitmq.client.ReturnCallback;
import com.yz.rabbitmq.ChannelsUtil;

import java.io.IOException;

public class LimitPro {
    public static void main(String[] args) throws IOException {
        Channel channel = ChannelsUtil.getChannel();
        channel.confirmSelect();
        for (int i=0;i<20;i++) {
            channel.basicPublish("fanoutExchange", "", true,null, ("hello world! "+ i).getBytes());
        }
        channel.addConfirmListener(new ConfirmListener() {
            @Override
            public void handleAck(long deliveryTag, boolean multiple) throws IOException {
                System.out.println("ack"+deliveryTag);
            }

            @Override
            public void handleNack(long deliveryTag, boolean multiple) throws IOException {
                System.out.println("ack"+deliveryTag);
            }
        });
        channel.addReturnListener(new ReturnCallback() {
            @Override
            public void handle(Return returnMessage) {
                System.out.println(new String(returnMessage.getBody()));
            }
        });
    }
}
